<?php
class PackageBillingAddress extends DataObject {
    private static $singular_name = "Package Billing Address";
    private static $plural_name = "Package Billing Addresses";

    private static $db = array(
        'Name' => 'Varchar(150)',
        'Contact' => 'Varchar',
        'Email' => 'Varchar'
    );

    private static function create_billing_address($data) {
        return PackageBillingAddress::create()->update($data)->write();
    }

    function getFrontEndFields($params = null) {
        $fields = parent::getFrontendFields($params);
        $fields->changeFieldOrder(array(
            'Name',
            'Contact',
            'Email',
            'Address',
            'Suburb',
            'State',
            'Postcode',
            'Country'
        ));
        $fields->insertBefore(HeaderField::create('AddressHeader', _t('PackageBillingAddress.BILLING_TO', 'Billing To'), 3), 'Name');
        $fields->replaceField('Email', EmailField::create('Email', $this->fieldLabel('Email')));
        return $fields;
    }

    /**
     * Returns the billing info in a simple HTML template.
     *
     * @return string
     */
    public function getTemplateHTML() {
        return $this->renderWith('PackageBillingInfo');
    }

    function canView($member = false) {
        return true;
    }

    function canEdit($member = false) {
        return false;
    }

    function canDelete($member = false) {
        return false;
    }

    function canCreate($member = false) {
        return false;
    }
}
?>